home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_11 / lusolv.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  664 b   |  23 lines  |  [MATF/MATL]

  1. function  [X,Y] = lusolv(A,B,row)
  2. % [X,Y] = lusolv(A,B,row)
  3. % The matrix A must be in factored LU form,
  4. % and row is the required pivoting information.
  5. % A  is the n x n matrix obtained from LUfact, input.
  6. % B is any nx1 vector, input.
  7. % row is the pivoting information from LUfact, input.
  8. % X is the solution to AX=B,  output.
  9. % Y is the solution to LY=PB, output.
  10. % Forward substitution followed
  11. % by back substitution is used.
  12. [n n] = size(A);
  13. Y = zeros(n,1);
  14. Y(1) = B(row(1));
  15. for k = 2:n,
  16.   Y(k) = B(row(k)) - A(row(k),1:k-1)*Y(1:k-1);
  17. end
  18. X = zeros(n,1);
  19. X(n) = Y(n)/A(row(n),n);
  20. for k = n-1:-1:1,
  21.   X(k) = (Y(k) - A(row(k),k+1:n)*X(k+1:n))/A(row(k),k);
  22. end
  23.